<template>
  <div class="container">
    <div class="top-box">
      <div class="left-box">
        <div class="color-box"></div>
        <p v-show="shows==2">采购计划入库</p>
        <p v-show="shows==0||shows==1">采购计划详情</p>
      </div>
      <div class="right-box">
        <el-button type="info" icon="el-icon-back" class="btn_fanhui" @click="Return">返回</el-button>
      </div>
    </div>
    <div class="content-box">
      <div class="table-box">
        <div class="up-box">采购计划表</div>
        <div class="bottom-box">
          <div class="item6-box">申请类型</div>
          <div class="item7-box">{{oneType}}</div>
        </div>
        <div class="conten-box">
          <el-table :data="list" border style="width: 100%">
            <el-table-column prop="date" label="序号" type="index" align="center" width="120"></el-table-column>
            <el-table-column prop label="名称" width="200" align="center">
              <template slot-scope="scope">
                <el-input type="text" v-model="scope.row.name"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop label="规格" align="center" width="120">
              <template slot-scope="scope">
                <el-input type="text" v-model="scope.row.standard"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop label="单位" align="center" width="120">
              <template slot-scope="scope">
                <el-input type="text" v-model="scope.row.unit"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop label="期初数" align="center" width="300">
              <template slot-scope="scope">
                <el-input type="text" v-model="scope.row.openblan"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop label="入库数" align="center" width="300">
              <template slot-scope="scope">
                <el-input type="text" v-model="scope.row.putin"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop label="出库数" align="center">
              <template slot-scope="scope">
                <el-input type="text" v-model="scope.row.outnum"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop label="库存数" align="center" width="120">
              <template slot-scope="scope">
                <el-input type="text" v-model="scope.row.inventorynum"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop label="备注" align="center" width="120">
              <template slot-scope="scope">
                <el-input type="text" v-model="scope.row.remark"></el-input>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div class="btn-box" v-show="shows==0">
        <el-button type="primary" @click="shenhe(1)">确定</el-button>
        <el-button type="primary" size="medium" @click="buohui">驳回</el-button>
      </div>
      <div class="btn-box" v-show="shows==2">
        <el-button type="primary" @click="addlist()">入库</el-button>
        <el-button type="info" @click="Return">返回</el-button>
      </div>
      <!-- 驳回弹框 -->
      <el-dialog title="驳回" :append-to-body="true" :visible.sync="dialogVisibles" width="30%">
        <div class="color_box"></div>
        <el-input
          type="textarea"
          :autosize="{ minRows: 2, maxRows: 4}"
          placeholder="请输入内容"
          v-model="main"
        ></el-input>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" type="primary" @click="shenhe(2)">确定</el-button>
          <el-button size="small" type="info" @click="dialogVisibles = false">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import axios from 'axios'
export default {
  data () {
    return {
      dialogVisibles: false,
      id: 0,
      shows: 1,
      oneType: "",
      list: [{
        name: "",
        standard: "",
        unit: "",
        openblan: "",
        putin: "",
        outnum: "",
        inventorynum: "",
        remark: ""
      }],
      Mark: 0,
      creater:0,
      main:""
    }
  },
  created () {
    this.creater = JSON.parse(localStorage.getItem("message")).Id;
    this.id = this.$route.query.e;
    this.shows = this.$route.query.shows;
    this.getlist()
  },
  methods: {
    buohui () { this.dialogVisibles = true; },
    shenhe (e) {
      if (this.Mark == 0) {
        if (e == 2) { if (this.main == "") { this.$message.error("驳回事由非空"); return } }
        var obj = { itemId: this.id, main: this.main, state: e, creater: this.creater };
        var objs = JSON.stringify(obj); let the = { index: 2, jsondata: objs };
        this.Mark = 1;
        axios.post("/apis/AdministrationManage.asmx/Examine", the).then(({ data }) => {
          var list = JSON.parse(data.d);
          if (list.flag == true) {
            this.$message.success(list.tip);
            setTimeout(() => {
              window.history.go(-1);
            }, 500);          }
          else { this.$message.error(list.tip); }
        })
      }

    },
    addlist (e) {
      if (this.Mark == 0) {
        var obj = { id: this.id, creater: this.creater };
        var objs = JSON.stringify(obj); let the = { index: 3, jsondata: objs };
        this.Mark = 1;
        axios.post("/apis/AdministrationManage.asmx/Examine", the).then(({ data }) => {
          var list = JSON.parse(data.d);
          if (list.flag == true) {
            this.$message.success(list.tip);
            setTimeout(() => {
              window.history.go(-1);
            }, 500);          }
          else { this.$message.error(list.tip); }
        })
      }

    },
    getSummaries (param) {
      const { columns, data } = param;
      console.log(param)
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += ' 元';
        } else {
          sums[index] = 'N/A';
        }
      });
      return sums;
    },
    Return () {
      window.history.go(-1);
    },
    getlist () {
      var obj = { id: this.id };
      var objs = JSON.stringify(obj);
      let the = { index: 15, jsondata: objs }
      axios.post("/apis/AdministrationManage.asmx/GetData", the).then(({ data }) => {
        var list = eval('(' + data.d + ')');
        // console.log(list);
        this.oneType = list.oneType;
        this.list = list.basemess;
      });
    },
  }
}
</script>
<style lang="scss" scoped>
@import '@/assets/scss/base.scss';
.top-box {
  width: 100%;
  height: 60px;
  overflow: hidden;
  // border: 1px solid $red;
}
.add-box {
  width: 10%;
  text-align: center;
  line-height: 70px;
  // border: 1px solid $red;
}
.left-box {
  width: 150px;
  height: 40px;
  float: left;
  margin-top: 10px;
  overflow: hidden;
  margin-left: 1%;
  // border: 1px solid red;
}
.color-box {
  width: 5px;
  height: 20px;
  float: left;
  margin-top: 10px;
  background-color: $Header_color;
}
.left-box p {
  float: left;
  margin-left: 5px;
  line-height: 40px;
}
.right-box {
  float: right;
  width: 90px;
  height: 40px;
  margin-right: 2%;
  border-radius: 8px;
  margin-top: 10px;
  background-color: $return-color;
  // border: 1px solid red;
}
.right-box:hover {
  background-color: #a4a6ad;
}
.right-box span {
  float: left;
  color: $white;
  font-size: $font-size-medium;
  line-height: 40px;
  //  border: 1px solid red;
}
.right-box img {
  width: 30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 6px;
  float: left;
  // border: 1px solid red;
}
.content-box {
  width: 98%;
  height: 720px;
  margin: 0 auto;
  border-radius: 8px;
  background-color: $white;
  border: 1px solid $bordercolor;
}
.up-box {
  width: 100%;
  height: 80px;
  line-height: 80px;
  text-align: center;
  font-size: $font-size-large;
  font-weight: bold;
  border-bottom: 1px solid $bordercolor;
}
.table-box {
  width: 94%;
  // height: 578px;
  margin: 0 auto;
  margin-top: 50px;
  //    border-top: 1px solid $bordercolor;
  //  border-left: 1px solid $bordercolor;
  //   border-right: 1px solid $bordercolor;
}
.bottom-box {
  display: flex;
  width: 100%;
  height: 70px;
  border-left: 1px solid $bordercolor;
  border-right: 1px solid $bordercolor;
}

.btom-box {
  width: 100%;
  overflow: hidden;
  border-bottom: 1px solid $bordercolor;
}
.xuhao-box {
  width: 9%;
  height: 60px;
  float: left;
  line-height: 60px;
  text-align: center;
  font-weight: bold;
  border-right: 1px solid $bordercolor;
  // border: 1px solid red;
}
.xuhao1-box {
  width: 18%;
  height: 60px;
  float: left;
  line-height: 60px;
  text-align: center;
  font-weight: bold;
  border-right: 1px solid $bordercolor;
  // border: 1px solid red;
}
.xuhao2-box {
  width: 9%;
  height: 60px;
  float: left;
  line-height: 60px;
  text-align: center;
  font-weight: bold;
  //border: 1px solid red;
}
.com-box {
  width: 100%;
  height: 60px;
  // border-bottom:1px solid  $bordercolor;
}
.conten-box {
  width: 100%;
}
.conten-box ul {
  overflow: hidden;
}
.conten-box ul li {
  width: 100%;
  height: 60px;
  // border-bottom:1px solid  $bordercolor;
}
.item6-box {
  width: 120px;
  height: 70px;
  float: left;
  line-height: 70px;
  text-align: center;
  font-weight: bold;
  border-right: 1px solid $bordercolor;
}
.item7-box {
  flex: 1;
  height: 70px;
  line-height: 70px;
  font-weight: bold;
  text-align: center;
}
.item-box {
  width: 120px;
  height: 60px;
  float: left;
  line-height: 60px;
  text-align: center;
  font-weight: bold;
  border-right: 1px solid $bordercolor;
}
.item-box input {
  width: 100%;
  height: 59px;
  border: none;
  outline: none;
  font-size: 14px;
}
.item1-box {
  width: 200px;
  height: 60px;
  float: left;
  line-height: 60px;
  text-align: center;
  font-weight: bold;
  border-right: 1px solid $bordercolor;
}
.item3-box input {
  width: 100%;
  height: 59px;
  border: none;
  outline: none;
  font-size: 14px;
}

input::-ms-input-placeholder {
  text-align: center;
}
input::-webkit-input-placeholder {
  text-align: center;
}
.item3-box {
  width: 110px;
  height: 60px;
  float: left;
  line-height: 60px;
  text-align: center;
  font-weight: bold;
  // border-right: 1px solid $bordercolor;
}
.btn-box {
  width: 20%;
  height: 60px;
  margin: 0 auto;
  margin-top: 20px;
  // border: 1px solid red;
}
</style>
